<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/public/base.jspf"%>
<body>
	<form id="addOrUpdate" method="post">
		<hidden id="hidden-params">
			<input id="btn_sub" type="hidden" onclick="submitForm()"/>
			<input id="parent_id" name="parentId" value="${m.parentId}" type="hidden"/>
			<input id="iconCls" name="iconCls" value="${m.iconCls}" type="hidden"/>
		</hidden>
	    <div>   
	        <label for="name">上级菜单:</label>
	        <input id="menu_tree_menu" />   
	    </div>
	    <div>   
	        <label for="text">名称:</label>
	        <input name="text" value="${m.text}" class="easyui-validatebox easyui-textbox" type="text" data-options="required:true" />
	    </div>
        <div>
		    <label for="type" class="ui-label">类型:</label>
		    <select name="type" class="easyui-combobox" data-options="editable:false" style="width:154px;">
			    <option value="1">菜单</option>
			    <option value="2">按钮</option>
		    </select>
        </div>
        <div>
        	<label for="level" class="ui-label">级别:</label>
            <select name="level" class="easyui-combobox" data-options="editable:false" style="width:154px;">
                <option value="1">一级菜单</option>
                <option value="2">二级菜单</option>
                <option value="3">三级菜单</option>
            </select>
        </div>
        <div>
	        <label for="name">URL:</label>   
	        <input value="${m.url }" class="easyui-validatebox easyui-textbox" type="text" name="url" data-options="required:true" />
	    </div>
	    <div id="icon_all">
	    	<label for="icons">图标:</label>
    		<select id="icons" style="width:154px"></select>
			<div id="icons-all">
				<div id="icons-temp" style="padding:10px;">
					
				</div>
			</div>
	    </div>
	</form>
	<script type="text/javascript">
		$(function(){
			var id = '${m.id}';
			$('#icons').combo({
				required:true,
				editable:false,
				panelWidth:350
			});
			$('#icons-all').appendTo($('#icons').combo('panel'));

			
			$.get('${xpath}/public/easyui.json',function(data){
				for (var i = 0; i < data.length; i++) {
					var t = '<i onclick="getIcon(\''+data[i].text+'\')" class="icon-span '+data[i].text+'"></i>';
					$('#icons-temp').append(t);
				}
			});

			$('#menu_tree_menu').combotree({    
			    url: 'loadSuperAdminMenu',
			    required: true,
			    panelWidth:200,
			    loadFilter:function(data){
		        	return data.obj;
		        },
		        onLoadSuccess:function(row,data){
		        	var parentId = '${m.parentId}';
		        	if(parentId!='' && parentId!=undefined){
		        		$('#menu_tree_menu').combotree('setValue',[parentId]);
		        	}
		        }
			});
			//如果不为空，表示修改操作
			if(id!='' && id!=undefined){
				$('#hidden-params').append('<input name="id" value="${m.id}" type="hidden" />');
				$('#hidden-params').append('<input name="_method" value="put" type="hidden"/>');
				$('#icons').combo('setValue', '${m.iconCls}').combo('setText', '${m.iconCls}').combo('hidePanel');
			}
		});
		//点击图标获取图标信息
		function getIcon(text){
			$('#icons').combo('setValue', text).combo('setText', text).combo('hidePanel');
		}
		function submitForm(){
			$('#addOrUpdate').form('submit', {
			    url:'manage',
			    onSubmit: function(params){
			    	//获取上级菜单ID
			    	var t = $('#menu_tree_menu').combotree('tree').tree('getSelected');	// 获取树对象选择的节点
			    	$('#parent_id').val(t.id);
			    	var icon = $('#icons').combo('getValue');
			    	$('#iconCls').val(icon);
			        return $(this).form('validate');
			    },
			    success:function(data){
			    	$.messager.alert('消息',eval('('+data+')').msg);
			    	$(this).parent().dialog('close');
			    	$('#tree_grid').treegrid('reload');	// 重新载入所有行
			    }
			});  
		}
		
	</script>
</body>